﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Shsc.Net.FrameWork.Common.Util
{
    public class StringUtil
    {

        /**
         * 右括弧
         */
        public static string RIGHT_KATU = ")";

        /**
         * 左括弧
         */
        public static string LEFT_KATU = "(";

        /**
         * "-"
         */
        public static string LINE = "-";

        /**
         * 半角コンマ
         */
        public static string COMMA = ",";

        /**
         * 半角スペース
         */
        public static string SPACE = " ";

        /**
         * 全角スペース
         */
        public static string ZENKAKU_SPACE = "　";

        /**
         * 全角スペース文字
         */
        public static char CHAR_ZENKAKU_SPACE = '　';

        /**
         * 半角スペース文字
         */
        public static char CHAR_SPACE = ' ';

        /**
         * TAB文字
         */
        public static char CHAR_TAB = '\t';
        // add by 李方力 for I1305/B-00582 on 2008/11/14

        /**
         * 改行コード（\r）
         */
        public static string SEPARATOR_R = "\r";
        // end add by 李方力 for I1305/B-00582 on 2008/11/14

        /**
         * 空文字
         */
        public static string BLANK = "";

        /**
         * {%
         */
        public static string STR_LEFTKAKKO = "{%";

        /**
         * UNDERLINE
         */
        public static string UNDERLINE = "_";

        /** File DOT: . */
        public static string DOT = ".";

        /**
         * WAVELINE
         */
        public static string WAVELINE = "～";
        /**
         * 半角,
         */
        public static string KANMA = ",";

        /**
         * コロン
         */
        public static string COLON = ":";

        /**
         * 分号
         */
        public static string SEMICOLON = ";";

        /**
         * 等号
         */
        public static string EQUALSIGN = "=";

        /**
         * 连接符
         */
        public static string AMPERSAND = "&";

        /**
         * 斜線
         */
        public static string OBLIQUELINE = "/";

        /**
         * 区切線
         */
        public static string SPLITLINE = ";";

        /** パーセント */
        public static string PERCENT = "%";

        /** 読点 */
        public static string TOUTEN = "、";

        /// <summary>
        /// Object存在判断
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>true:为空, false：不为空</returns>
        public static bool IsEmpty(object obj)
        {
            if (obj == null)
            {
                return true;
            }

            if (obj is string)
            {
                if (string.IsNullOrEmpty(obj as string))
                {
                    return true;
                }
            }
            else if (obj is ICollection)
            {
                if (((ICollection)obj).Count == 0)
                {
                    return true;
                }
            }


            return false;
        }

        /// <summary>
        /// str为空的场合，返回string.Empty
        /// </summary>
        /// <param name="str">文字列</param>
        /// <returns></returns>
        public static string Nvl(string str)
        {
            if (IsEmpty(str))
            {
                return string.Empty;
            }
            return str;
        }

        /// <summary>
        /// 左边补入对应字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="len"></param>
        /// <param name="chr"></param>
        /// <returns></returns>
        public static string PadLeft(string str, int len, char chr)
        {
            string tmpStr = str;
            if (IsEmpty(tmpStr))
            {
                return BLANK;
            }

            StringBuilder buf = new StringBuilder(tmpStr);
            while (buf.Length < len)
            {
                buf.Insert(0, chr);
            }
            return buf.ToString();
        }

        /// <summary>
        /// 右边补入对应字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="len"></param>
        /// <param name="chr"></param>
        /// <returns></returns>
        public static string PadRight(string str, int len, char chr)
        {
            string tmpStr = str;
            if (IsEmpty(tmpStr))
            {
                return BLANK;
            }

            StringBuilder buf = new StringBuilder(tmpStr);
            while (buf.Length < len)
            {
                buf.Append(chr);
            }
            return buf.ToString();
        }
    }
}
